<template>
  <div style="width: 100%;height: 100%">
    <el-menu :default-openeds="defaultOpens" background-color="rgb(48, 65, 86)"
             text-color="#fff" style="height: 100%;overflow-x: hidden"
             active-text-color="#ffd04b"
             :collapse="isCollapse"
             :collapse-transition="false"
             router
    >
      >
      <!--   router属性：启动路由模式, 和index配合使用，就能实现router-link的作用   -->
      <div style="height: 60px;line-height: 60px;text-align: center">
        <img src="../assets/logo.png" alt="图片" style="width: 20px;position: relative;top: 5px;margin-left: 5px">
        <b style="color: white" v-show="logoTextShow">后台管理系统</b>
      </div>

      <!--  动态路由 -->
      <div v-for="item in menus">
        <div v-if="item.path">
          <el-menu-item :index="item.path">
            <i :class="item.icon"></i>
            <span v-show="!isCollapse">{{ item.name }}</span>
          </el-menu-item>
        </div>
        <div v-else>
          <el-submenu :index="item.id+''">
            <!--     index：绑定值要求是字符串   -->
            <template slot="title">
              <i :class="item.icon"></i>
              <span  v-show="!isCollapse">{{ item.name }}</span>
            </template>
            <el-menu-item-group>
              <template v-for="subItem in item.children">
                <el-menu-item :index="subItem.path">
                  <i :class="subItem.icon"></i>
                  <span slot="title"> {{ subItem.name }}</span>
                </el-menu-item>
              </template>
            </el-menu-item-group>
          </el-submenu>
        </div>
      </div>
    </el-menu>
  </div>
</template>

<script>
export default {
  props: {
    isCollapse: {
      type: Boolean,
      default: false
    },
    logoTextShow: {
      type: Boolean,
      default: true
    },
  },
  data() {
    return {
      // 菜单数据
      menus: [],
      // 默认展开的菜单
      defaultOpens: [],
    }
  },
  methods: {},
  mounted() {
    let username = JSON.parse(localStorage.getItem("user"))
    this.menus = username.menus;
    this.defaultOpens = this.menus.map(item => item.id + '');

  }
}
</script>


<style scoped>

</style>